import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    private static final String[] SUITS = {"♦","♥","♠","♣"};

    public static List<Card> buyCard(){
        List<Card> list = new ArrayList<>();
        for (int i = 1; i <= 13 ; i++) {
            for (int j = 0; j < SUITS.length; j++) {
                String suit = SUITS[j];
                int rank = i;
                Card card = new Card(SUITS[j], i);
                list.add(card);
            }
        }return list;
    }
    public static void shuffle(List<Card> list){//洗牌
        Random random = new Random();
        for (int i = list.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);//随机生成的数字存入index中；
            exchange(list,i,index);
        }
    }
    private static void exchange(List<Card> list,int i,int j){
        Card swap = list.get(i);
        list.set(i,list.get(j));//将j下标的牌赋值给i下标的牌
        list.set(j,swap);
    }
    public static void main(String[] args) {
        List<Card> list = buyCard();
        System.out.println(list);
        shuffle(list);
        System.out.println(list);
        List<List<Card>> hand = new ArrayList<>();//二维数组
        List<Card> hand1 = new ArrayList<>();//二维数组的0下标，此时也代表抓牌的人。
        List<Card> hand2 = new ArrayList<>();//二维数组的1下标
        List<Card> hand3 = new ArrayList<>();//二维数组的2下标
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("第1个人的牌："+hand.get(0));
        System.out.println("第2个人的牌："+hand.get(1));
        System.out.println("第3个人的牌："+hand.get(2));
        System.out.println("剩下的牌："+list);
    }
}
